﻿@page "/report"

<h4>Report</h4>
<div class="container-fluid bg-custom my-1 pb-1">
@if (Runs.Count > 0)
{
    <div class="run-box bg-custom">
        <div class="form-inline">
            <label class="mr-2" for="RunId">Run ID:</label>
            <select class="form-control mr-3" id="RunId" @bind="RunIdInput">
            @for (int i = 0; i < Runs.Count; i++)
            {
                if (!string.IsNullOrEmpty(@Runs[i].firstRunId))
                {
                    <option value="@i">@Runs[i].firstRunId vs @Runs[i].secondRunId (@Runs[i].runStatus)</option>
                }
                else{
                    <option value="@i">@Runs[i].secondRunId (@Runs[i].runStatus)</option>
                }
            }
            </select>
        </div>
    </div>
    <Results FirstRunId="@Runs[RunIdInput].firstRunId" SecondRunId="@Runs[RunIdInput].secondRunId" AnalysesHash="@Runs[RunIdInput].analysesHash" MonitorRunId="@Runs[RunIdInput].secondRunId" />
}
else
{
    <p>No results available.</p>
    <p>Please run comparisons before viewing results.</p>
}
</div>

@code {

    List<(string firstRunId, string secondRunId, string analysesHash, RUN_STATUS runStatus)> Runs = AttackSurfaceAnalyzerClient.DatabaseManager.GetCompareRuns();

    private int _runIdInput;

    int RunIdInput
    {
        get
        {
            return _runIdInput;
        }
        set
        {
            appData.ExportCollectCommandOptions.FirstRunId = Runs[value].firstRunId;
            appData.ExportCollectCommandOptions.SecondRunId = Runs[value].secondRunId;
            _runIdInput = value;
            this.StateHasChanged();
        }
    }
}
